//
//  UserDefaultsHelper.m
//  BasketballHelper
//
//  Created by Fedora on 2024/5/15.
//

#import "UDSaveCountData.h"

#define COUNTDATAKEY  @"CountDataKey"

@implementation UDSaveCountData

//save array
+ (void)saveCountData:(NSString *)string {
    // 使用NSUserDefaults存储数组
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSMutableArray *array = [NSMutableArray arrayWithArray:[UDSaveCountData getAllCountData]];
    [array insertObject:string atIndex:0];
    [defaults setObject:array forKey:COUNTDATAKEY];
    [defaults synchronize]; // 确保数据被立即写入磁盘
}

//get array 从NSUserDefaults读取数组
+ (NSArray *)getAllCountData {
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSArray *array = [defaults objectForKey:COUNTDATAKEY];;
    return array;
}


+ (void)clearCountHistoryData {
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults removeObjectForKey:COUNTDATAKEY];
    [defaults synchronize];
}

+ (NSInteger)getAllCountDataCount {
    return [UDSaveCountData getAllCountData].count;
}

@end
